import type { Profile } from '@/types/user'
import { getLocalToken, removeLocalToken, setLocalToken } from '@/utils/auth'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user', () => {

 // 获取token
 const token = ref(getLocalToken() || '')
 // 设置token
 const setToken = (val: string) => {
   token.value = val
   // 本地持久化token
   setLocalToken(val)
 }
 // 移除token
 const removeToken = () => {
   token.value = ''
   // 移除本地token
   removeLocalToken()
 }


 // 设置登录人信息  // 获取用户信息
  const profile = ref<Profile>({} as Profile)

  const setProfile = (val: Profile) => {
    profile.value = val
  }
  const removeProfile = () => {
    profile.value = {} as Profile
  }

  return {
    token,
    setToken,
    removeToken,
    profile,
    setProfile,
    removeProfile
  }
})
